package com.wuhuahe.luanfeng;

import org.junit.Assert;
import org.junit.Test;

/**
 * Created By wuhuahe
 * author:游龙
 * Date: 2018-07-23
 * Time: 20:50
 * Desc:
 */
public class Factorial {

    public static long factorial(int n){
        return loop(n, 1);
    }

    private static long loop(int n, long acc){
        if(n <= 1) return  acc;
        else return loop(n - 1, n * acc);
    }

    @Test
    public void testFactorial(){
        Assert.assertEquals(5 * 4* 3* 2*1, factorial(5));
    }
}
